package com.ikas.ai.utils;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class XmlUtil {

    private static Logger logger = LoggerFactory.getLogger(XmlUtil.class);

    private XmlUtil() {

    }

    public static void write(String path, String fileName, Document document) {
        try {
            OutputFormat formater = OutputFormat.createPrettyPrint();
            formater.setIndentSize(4);
            formater.setEncoding(document.getXMLEncoding());
            FileOutputStream file = new FileOutputStream(path + File.separatorChar + fileName);
            XMLWriter xmlWriter = new XMLWriter(file, formater);
            xmlWriter.write(document);

            xmlWriter.close();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

}
